<%@	taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ tag pageEncoding="UTF-8"%>
<%@ attribute name="addOnProdTypeInvMap" required="true" type="java.util.Map"%>
<%@ attribute name="prodSpecMajorMap" required="true" type="java.util.Map"%>
<%@ attribute name="addOnProdTypes" required="true" type="java.util.List"%>
function selectMainSpec(prodId, msId){
if($(":select[id*=selectMs_"+prodId+"]").length==0){
return;
}
	var secSpec = $("#selectMs_"+prodId).data(msId);
	var secSpecHtml = '';
	if(secSpec == null || $(secSpec).length>1){
		secSpecHtml = '<option value="">请选择</option>';
	}
	if(secSpec != null){
		$(secSpec).each(function(index, temp) {
		
			if(parseInt($(document.body).data('inv_'+temp.specId))>0){
				secSpecHtml += "<option value=\""+temp.specId+"\">"+temp.specName+"</option>";
			}else{
				secSpecHtml += "<option value=\""+temp.specId+"\" disabled=\"disabled\">"+temp.specName+"-售完</option>";
			}
		});
	}
	$(":select[id*=selectMs_"+prodId+"] option:[value="+msId+"]").attr("selected","true");
	$(":select[id*=selectSs_"+prodId+"]").html(secSpecHtml);
	$(":select[id*=selectSs_"+prodId+"]").change(function(){
		var ssId = $(this).val();
		$(":select[id*=selectSs_"+prodId+"] option:[value="+ssId+"]").attr("selected","true");
	});
	
}

$().ready(function(){
//加购商品
$(":select[id*=selectMs_]").change(function(){
	var aopId = $(this).attr('id').split('_')[1];
	var msId = $(this).val();
	selectMainSpec(aopId,msId);
});

<c-rt:forEach items="${addOnProdTypeInvMap}" var="entry">
<c-rt:if test="${entry.key ne 'present'}">$(document.body).data('inv_${entry.key}',${entry.value});</c-rt:if>
</c-rt:forEach>
var aopSecSpec;
var aopHaseQty;
<c-rt:set var="pcounter" value="0" />
<c-rt:forEach items="${addOnProdTypes}" var="addOnProduct" varStatus="status">
	<c-rt:set var="pcounter" value="${pcounter+10}" />
	<c-rt:forEach items="${prodSpecMajorMap[addOnProduct.addOnProductId]}" var="addOnProductSpecMajor" varStatus="status">
		$("#selectMs_${addOnProduct.addOnProductId}").data('${addOnProductSpecMajor.mainSpecId}',${addOnProductSpecMajor.jsonDetail});
		aopSecSpec = ${addOnProductSpecMajor.jsonDetail};
		aopHaseQty = false;
		$(aopSecSpec).each(function(index, temp) {
			if(parseInt($(document.body).data('inv_'+temp.specId))>0){aopHaseQty = true;}
		});
		if(!aopHaseQty){
			$(":option[value=${addOnProductSpecMajor.mainSpecId}]").attr('disabled','disabled').append('-售完');
		}
	</c-rt:forEach>
	<c-rt:if test="${fn:length(prodSpecMajorMap[addOnProduct.addOnProductId]) == 1}">
	setTimeout("selectMainSpec('${addOnProduct.addOnProductId}',$('#selectMs_${addOnProduct.addOnProductId}').val());",${pcounter});
	</c-rt:if>
</c-rt:forEach>
});